package top.wilsonlv.jaguar.dept.data.permission;

import top.wilsonlv.jaguar.basecrud.util.LongUtil;
import top.wilsonlv.jaguar.commons.web.exception.impl.CheckedException;
import top.wilsonlv.jaguar.security.model.SecurityUser;
import top.wilsonlv.jaguar.security.util.SecurityUtil;

/**
 * @author lvws
 * @since 2022/8/11
 */
public class DeptDataPermissionUtil {

    public static void checkPermission(Long deptId) {
        SecurityUser currentUser = SecurityUtil.getCurrentUser();
        if (LongUtil.isNull(currentUser.getDeptId())) {
            return;
        }

        boolean hasPermission = currentUser.getGrantedDeptIds().contains(deptId);
        if (!hasPermission) {
            throw new CheckedException("您没有目标部门管理权限");
        }
    }

}
